#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
    pid_t pid = fork();

    if(pid < 0){
        perror("fork error\n");
        return 1;
    }

    if(pid == 0){   //child
        int cnt;
        for(cnt = 0;cnt < 7;cnt++){
            printf("childproc[%d] is running.....\n", getpid());
            sleep(1);
        }
        exit(0);
    }

    printf("father before....\n");
    pid_t ret = waitpid(pid, NULL, 0);

    if(ret > 0){   //success
        printf("wait success\n");
    }
    else{
        printf("wait failed\n");
    }
    printf("father after....\n");
    return 0;
}

